package v2;

import java.util.Vector;

/**
 * @Description: 敌人坦克
 * @CreateTime: 2024-01-25  15:25
 * @Author: JAMILA
 * @Version: 1.0
 */

public class EnemyTank extends Tank implements Runnable {

    private Vector<Shot> shots = new Vector<>();
    private boolean isLive = true;

    public Vector<Shot> getShots() {
        return shots;
    }

    public void setShots(Vector<Shot> shots) {
        this.shots = shots;
    }

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    public EnemyTank(int x, int y, int direct, int speed) {
        super(x, y, direct, speed);
    }

    @Override
    public void run() {
        while (true) {
            //判断敌人坦克存活状态，如果存活则自由移动
            if (isLive) {
                //根据坦克的方向继续移动一下
                switch (getDirect()) {
                    case 0://向上
                        //让敌人坦克保持一个方向走30步
                        for (int i = 0; i < 30; i++) {
                            moveUp();
                            try {
                                Thread.sleep(50);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        break;
                    case 1://向右
                        for (int i = 0; i < 30; i++) {
                            moveRight();
                            try {
                                Thread.sleep(50);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        break;
                    case 2://向下
                        for (int i = 0; i < 30; i++) {
                            moveDown();
                            try {
                                Thread.sleep(50);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        break;
                    case 3://向左
                        for (int i = 0; i < 30; i++) {
                            moveLeft();
                            try {
                                Thread.sleep(50);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        break;
                }

                //随机改变坦克方向
                setDirect((int) (Math.random() * 4));
            } else {
                break;
            }
        }

    }
}
